package com.company.card_service.serviceImpl;

import com.company.card_service.mapper.MessageMapper;
import com.company.card_service.model.Message;
import com.company.card_service.model.Reply;
import com.company.card_service.mapper.ReplyMapper;
import com.company.card_service.service.ReplyService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.company.card_service.vo.ReplyVo;
import com.company.card_service.vo.Result;
import com.company.card_service.vo.ResultCodeEnum;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 赵志浩
 * @since 2022-09-15 04:15:07
 */
@Service
public class ReplyServiceImpl extends ServiceImpl<ReplyMapper, Reply> implements ReplyService {
    @Autowired
    private ReplyMapper replyMapper;

    @Autowired
    private MessageMapper messageMapper;
    //员工回复留言
    @Override
    public Result addReply(Reply reply,Integer messageId) {
        Message message = messageMapper.selectById(messageId);
        message.setIsReply(1);
        reply.setCreateTime(new Date());
        reply.setIsDeleted(0);
        int i = replyMapper.insert(reply);
        message.setReplyId(reply.getId());
        messageMapper.updateById(message);
            return Result.success(ResultCodeEnum.SUCCESS.getCode(),ResultCodeEnum.SUCCESS.getMessage());
    }

    @Override
    public void updateReplyById(ReplyVo replyVo) {
        Reply reply = new Reply();
        BeanUtils.copyProperties(replyVo,reply);
        if(reply.getId() != null){
            this.replyMapper.updateById(reply);
        }

    }

}
